//
//  ThemeColorPicker.swift
//  HeadlineNews
//
//  Created by han on 2019/7/24.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

final class ThemeColorPicker: ThemePicker {
    
    convenience init(keyPath: String) {
        self.init(v: { ThemeManager.color(for: keyPath) })
    }
    
    convenience init(keyPath: String, map: @escaping (Any?) -> UIColor?) {
        self.init(v: { map(ThemeManager.value(for: keyPath)) })
    }
    
    convenience init(colors: String...) {
        self.init(v: { ThemeManager.colorElement(for: colors) })
    }
    
}

extension ThemeColorPicker: ExpressibleByArrayLiteral {
    convenience init(arrayLiteral elements: String...) {
        self.init(v: { ThemeManager.colorElement(for: elements) })
    }
}

extension ThemeColorPicker: ExpressibleByStringLiteral {
    convenience init(stringLiteral value: String ) {
        self.init(keyPath: value)
    }
    
    convenience init(extendedGraphemeClusterLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeColorPicker: ExpressibleByUnicodeScalarLiteral {
    convenience init(unicodeScalarLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeColorPicker {
    class func pickerWithKeyPath(_ keyPath: String) -> ThemeColorPicker {
        return ThemeColorPicker(keyPath: keyPath)
    }
    
    class func pickerWithKeyPath(_ keyPath: String, map:@escaping (Any?) -> UIColor?) -> ThemeColorPicker {
        return ThemeColorPicker(v: { map(ThemeManager.value(for: keyPath))})
    }
    
    class func pickerWithColors(_ colors: [String]) -> ThemeColorPicker{
        return ThemeColorPicker(v: { ThemeManager.colorElement(for: colors) })
    }
}


